package com.linxianqin.log.manager;

import com.linxianqin.log.domain.dto.SysLogDto;
import com.linxianqin.log.utils.http.AddressUtils;
import com.linxianqin.log.utils.spring.SpringUtil;
import com.linxianqin.log.service.SysLogService;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

import java.util.TimerTask;

/**
 * 功能描述：异步工厂（产生任务用）
 *
 * @author 林贤钦
 * @version 1.00
 * @Date 2020/12/8
 */
public class AsyncFactory {
    private final static Log logger = LogFactory.getLog(AsyncFactory.class);
    /**
     * 操作日志记录
     *
     * @param sysLogDto 操作日志信息
     * @return 任务task
     */
    public static TimerTask recordOper(final SysLogDto sysLogDto)
    {
        return new TimerTask()
        {
            @Override
            public void run()
            {
            // 远程查询操作地点
            sysLogDto.setOperLocation(AddressUtils.getRealAddressByIP(sysLogDto.getOperIp()));
            logger.info("异步操作日志信息:"+ sysLogDto);
            SpringUtil.getBean(SysLogService.class).saveLog(sysLogDto);
            }
        };
    }
}
